<template>
	<view class="content">
		<view class="topcomtent">
		<view class="login-screen-title">
									<!--<i class="f7-icons">add_round</i>-->
		
		<view class="gdzc">Hi,欢迎登录</view>
		<view class="gdzc_lable">国泰君安证券 － 固定资产管理系统</view>
		</view>
		</view>
		<view style="padding: 0 25rpx;">
			<view
			style="height: 130rpx;line-height: 130rpx;font-weight: bold;
			color:#6D8AF9;font-size: 38rpx;padding-left: 15rpx;"
			>登 录</view>
			<view class="row" style=" border-bottom: 1px solid #f8f8f8 !important;">
						<view style="position:absolute;margin-top: 8px;">
							<image src="../../static/images/icon-myuser-ed-login.png" class="item-icon" mode=""></image>
						</view>
						<input v-model="username" type="text" placeholder="请输入用户名" />
					</view>
			
					<view class="row" style=" border-bottom: 1px solid #f8f8f8 !important;">
						<view style="position:absolute;margin-top: 8px;">
							<image src="../../static/images/icon-password.png"  class="item-icon" mode="" ></image>
						</view>
						<input v-model="pwd" type="password" placeholder="请输入密码" />
					</view>
					<view class="row">
						<view style="margin-right: 15rpx;">
							<image :src="checkurl"  class="item-icon" mode="" @tap="checkicon"></image>
							
						</view>
						<view style="font-size: 28rpx;margin-top: 2px;color:#6D8AF9;">
							保存密码
						</view>
			
						</view>
					<view class="btg">
						<button type="primary" @tap="btn" :disabled="loginStr!='登录'">
							<span>{{loginStr}}</span>
						</button>
					</view>
		</view>
	</view>
</template>

<script>
	import md5 from './md5.js'
	var self;
	export default {
		data() {
			lists: [],
			self = this
			return {
				username: '',
				pwd: '',
				ischeck:0,
				checkurl:"../../static/images/icon-uncheck.png",
				loginStr:"登录"
			}
		},
		onLoad(){
			
			uni.setStorage({
				key: 'localurl',
				data: "http://47.100.57.58"
			});
			
			uni.removeStorageSync("IdexSumCount");
			uni.removeStorageSync("IdexSumCount_ZY");
			uni.removeStorageSync("IdexSumCount_XZ");
			uni.removeStorageSync("IdexSumCount_JY");
			uni.removeStorageSync("IdexSumCount_YF");
			uni.removeStorageSync("MyAPPUserModel");
			
		},
		onBackPress(options) {
			//plus.runtime.quit();
			return true //return true的意思是禁止返回到上一个界面
			},
		created() {
			self=this;
			uni.getStorage({
				key: "syloginname",
				success: function(newres) {
					console.log(newres);
					self.username=newres.data;
					self.ischeck=1;
					self.checkurl="../../static/images/icon-check.png";
				}
			});
			uni.getStorage({
				key: "syloginpwd",
				success: function(newres) {
					console.log(newres);
					self.pwd=newres.data;
				}
			});
						//syloginpwd   
								   
				uni.removeStorageSync("IdexSumCount");
				uni.removeStorageSync("IdexSumCount_ZY");
				uni.removeStorageSync("IdexSumCount_KC");			
				uni.removeStorageSync("IdexSumCount_XZ");
				uni.removeStorageSync("IdexSumCount_JY");
				uni.removeStorageSync("IdexSumCount_YF");
				uni.removeStorageSync("MyAPPUserModel");				   
			},
		methods: {
			btn() {
				if(this.ischeck){
					uni.setStorage({
						key:"syloginname",
						data:this.username
					})
					uni.setStorage({
						key:"syloginpwd",
						data:this.pwd
					})
				}else{
					uni.removeStorageSync("syloginname");
					uni.removeStorageSync("syloginpwd");
				}
				
				if (this.username.length <= 0) {
					uni.navigateTo({
						url: '../stock/StockDocumentDetailSearch?Search=' + this.searchtext+"&Type=assetlist",
					});
					return;
				}
				if (this.pwd.length <= 0) {
					uni.showToast({
						icon: 'none',
						title: '请输入密码'
					});
					return;
				}
				self.loginStr="登录中...";
				uni.showNavigationBarLoading();//显示加载动画
				console.log("请求");
				uni.request({
					url:uni.getStorageSync("localurl")+'/console/app/v1/auth/login', //仅为示例，并非真实接口地址。
					data: {
						loginName: this.username,
						password: md5(this.pwd),
					},
					method: "POST",
					success: (res) => {
						uni.hideNavigationBarLoading();
						console.log("返回");
						console.log(res);
						if (res.data.code==2000) {
							
							uni.hideNavigationBarLoading();
							uni.setStorage({
								key: 'LoginName',
								data: {
									LoginName: this.username
								}
							});
							uni.setStorage({
								key: 'userInfo',
								data:JSON.stringify(res.data.map.userInfo)
								
							});
							uni.setStorage({
								key: 'authorization',
								data:res.data.data
								
							});
							uni.setStorage({
								key: 'userToken',
								data:res.data.map.userToken
								
							});
							
							uni.setStorage({
								key: 'userRoles',
								data:res.data.map.userRoles
								
							});
							uni.setStorage({
								key: 'userDept',
								data:res.data.map.userDept
								
							});
							uni.setStorage({
								key: 'userReadDeptIds',
								data:res.data.map.userReadDeptIds
								
							});
							uni.setStorage({
								key: 'managePositionIds',
								data:res.data.map.managePositionIds
								
							});
							self.loginStr="登录";
							uni.setStorageSync('setStatusIndexFunc', 0);
							uni.navigateTo({
								url: '../home/Index?LoginName=' + this.username,
							});
							//managePositionIds
						} else {
							self.loginStr="登录";
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
							return;
						}

						//window.location.href = 'http://43.254.46.191:7923/MoblieApp/h5/index.html#/pages/home/Index?LoginName=' + this.username
					//window.location.reload();

					},
					fail: () => {
						self.loginStr="登录";
						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}


				});
			},
			checkicon(){
				if(this.ischeck==0){
					this.ischeck=1;
					//uni.setStorage()
					this.checkurl="../../static/images/icon-check.png";
				}else{
					this.ischeck=0;
					this.checkurl="../../static/images/icon-uncheck.png";
				}
			},
			change(){
				
				uni.navigateTo({
					url: '../home/hrefchange'
				});
				//window.location.href = '/moblieapp/h5/index.html#/pages/home/hrefchange';
			}
		}
	}
</script>

<style>
	.gdzcold{
		float:left;
		margin-left: 10rpx;
		color:#6D8AF9;
		font-size: 28px !important;
		margin-top: 150rpx;
		
	}
	.gdzc{
		float:left;
		margin-left: 25rpx;
		color:#FFFFFF;
		font-size: 32px !important;		
		font-weight: bold;
		text-align: left;
		margin-top: 44% !important;
		
	}
	.gdzc_lable{
		float:left;
		margin-left: -47.5%;
		
		color:#FFFFFF;
		font-size: 32rpx !important;				
		font-weight: bold;
		margin-top: 60% !important;
		text-align: left;
		font-family:iconfont;
		
	}
	.item-icon {
		width: 40upx;
		height: 40upx;
	}
	.content {
		min-height: 100%;
		flex: 1;
		flex-direction: column;
		padding-top: 0rpx;
	}
	.content .topcomtent{
		background-color: #6D8AF9;
		height: 600rpx;
		padding-left: 15rpx;
		}

	.btg {
		margin-top: 10px;
	}
	.btg button{
		background-color:#6D8AF9 !important;
		margin-top: 20px;
	}

	.row {
		margin-top: 10rpx;
		display: flex;
		flex-direction: row;
		position: relative;
		background-color: #ffffff;
		margin-bottom: 10px;
		padding-left: 15rpx;
	}

	.group {
		background-color: #ffffff;
		position: relative;
	}

	.row input {
		width: 90%;
		height: 50rpx;
		min-height: 50rpx;
		padding: 15rpx 0;
		padding-right: 30px;
		line-height: 30px;
		margin-left: 30px;
	}

	.row .title {
		width: 30%;
		height: 25px;
		min-height: 25px;
		padding: 15px 0;
		padding-left: 30px;
		line-height: 25px;
		
	}

	.group {
		background-color: #ffffff;
		margin-top: 40px;
		position: relative;
	}
	
	
	/***登录模板 start***/
	.login-screen-title{
		height: 100%;
		text-align: center;
		
	}
	.login-screen-title image {
		width: 216px;
		
	}
	.login-screen-title p{
		color: #004E97;
	    font-size: 24px;
	    text-align: center;
	    margin: 10px 0;
	    font-weight: bold;
	}
	.login-icon-fang{
	    width: 56rpx;
	    height: 56rpx;		
	}
	.login-icon{
	    width: 194px;
	    height: 56px;
		
	}
	
	
	.ItemCheck{
		font-size: 28rpx;
		color: #D3D3D3;
	}
</style>
